using System;
using System.Collections.Generic;
using System.Text;

namespace RapidHDL.Fabric
{
    public class ProgramROMBlock : Block 
    {
        ProgramTable oProgram;
        
        public ProgramROMBlock(string psName, MicroCoreTable poOpTable,  string psFilePath)
            : base(psName,"PROG")
        {
            oProgram = new ProgramTable(poOpTable);
            oProgram.CompileResourceToROM(psFilePath);

            this.CreateInput("PC", oProgram.PCWidth);
            this.CreateOutput("CONST", oProgram.ConstWidth);
            this.CreateOutput("IR", oProgram.IRWidth);
        }

        internal override void GenerateStructure()
        {
            ProgramROM oPROM = new ProgramROM(ParentComponent, "prom_" + Name, oProgram);

            NodeVector nvPC = ParentComponent.CreateNodeVector("pc_I", Inputs["PC"].Width);
            Inputs["PC"].LinkNodeVector(nvPC);

            NodeVector nvConst = ParentComponent.CreateNodeVector("const_O", Outputs["CONST"].Width);
            Outputs["CONST"].LinkNodeVector(nvConst);

            NodeVector nvIR = ParentComponent.CreateNodeVector("ir_O", Outputs["IR"].Width);
            Outputs["IR"].LinkNodeVector(nvIR);


            oPROM.I_PC.Join(Inputs["PC"].NodeVector);
            oPROM.O_CONST.Join(Outputs["CONST"].NodeVector);
            oPROM.O_IR.Join(Outputs["IR"].NodeVector);
        }
    }
}
